/**
 * Created by ZMoffice on 2017-06-12.
 */
var ab = document.getElementById('old').value;
var ac = document.getElementById('new').value;
var ad = document.getElementById('newa').value;
$(" #old").focus(function () {
    $("#old").attr("type", "text");
    $("#new").attr("type", "password");
    $("#newa").attr("type", "password");

});
$("#old").blur(function () {
    $("#old").attr("type", "password");
    ab = document.getElementById('old').value;
    if (ab == "") {
        $("#empty_old").show();
    } else {
        $("#empty_old").hide();

    }
});
$(" #new").focus(function () {
    $("#new").attr("type", "text");
    $("#old").attr("type", "password");
    $("#newa").attr("type", "password");

});
$("#new").blur(function () {
    $("#new").attr("type", "password");
    ac = document.getElementById('new').value;
    ad = document.getElementById('newa').value;

    if (ac == "") {
        $("#empty_new").show();
        $("#atypism").hide();

    } else {
        $("#empty_new").hide();
        if (ad == ac) {
            $("#atypism").hide();

        } else {
            $("#empty_newa").hide();

            $("#atypism").show();

        }
    }
});
$(" #newa").focus(function () {
    $("#newa").attr("type", "text");
    $("#old").attr("type", "password");
    $("#new").attr("type", "password");
});
$("#newa").blur(function () {
    $("#newa").attr("type", "password");
    ac = document.getElementById('new').value;

    ad = document.getElementById('newa').value;

    if (ad == "") {
        $("#atypism").hide();
        $("#empty_newa").show();

    } else {
        $("#empty_newa").hide();
        if (ad == ac) {
            $("#atypism").hide();

        } else {
            $("#empty_newa").hide();
            $("#atypism").show();

        }
    }
});
var BASEAPI = "http://localhost:8080/helipay.api.web/";
var b = 0; //全局变量
var session = sessionStorage.getItem("session"); //获取登录后的session
var sessiona = sessionStorage.getItem("session"); //获取登录后的session
var managementuser = sessionStorage.getItem("managementuser"); //获取登录后的商家名字
var managementuserA = sessionStorage.getItem("managementuserA"); //获取登录后的商家名字
var session = '欢迎' + managementuser;
$(".header_right_user").append(session);

if (session == null || session == undefined) {
    alert("请重新登录！")
    window.location.href = 'index';
} else if (managementuser == null) {
    alert("请重新登录！")
    window.location.href = 'index';
}

function revise() {
    var ab = document.getElementById('old').value;
    var ac = document.getElementById('new').value;
    var ad = document.getElementById('newa').value;
    var newPassword = hex_md5(ac);
    var oldPassword = hex_md5(ab);
    var param = {
        newPassword: newPassword,
        oldPassword: oldPassword,
        session: sessiona,
        customerNumber: managementuserA,
    }
    //				console.log(param)
    if (ba == '') {
        alert("原始密码不能为空！");
    } else if (ab == '') {
        alert("新密码不能为空！");
    }else if(ad==""){
        alert("确认密码不能为空！");
    }else if (newPassword == oldPassword) {
        alert("原始密码和新密码不能相同！");
    }else if(!ac==ad){
        alert("新密码和确认密码不相同！");

    } else {
        $.ajax({
            url: BASEAPI + 'changePassword',
            type: 'GET',
            data: param,
            dataType: 'json',
            success: function (data) {
                if (data.errorCode == '0000') {
                    alert("成功修改密码！");
                    //							console.log(data);
                    window.location.href = 'main';
                } else {
                    console.log(data.errorMessage);
                    alert(data.errorMessage);
                }

            },
            error: function (err) {
                console.log(err)
                alert("连接服务器失败！请重新提交！")
            }
        });
    }
}

function re() {
    window.location.href = 'main';

}